package com.hujing.springsource.a13;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * 手写jdk代理类,模拟jdk代理的实现原理
 */
public class A13 {

    interface Foo {
        Object foo();
    }

    interface Bar {
        Object bar();
    }

    static class Target implements Foo, Bar {
        @Override
        public Object foo() {
            System.out.println("Target foo()");
            return null;
        }

        @Override
        public Object bar() {
            System.out.println("Target bar()");
            return null;
        }
    }

    interface InvocationHandler {
        Object invoke(Method method, Object[] args) throws Throwable;
    }

    public static void main(String[] args) {
        $Proxy0 $Proxy0 = new $Proxy0(new InvocationHandler() {
            @Override
            public Object invoke(Method method, Object[] args) throws InvocationTargetException, IllegalAccessException {
                System.out.println("before invoke");
                Object result = method.invoke(new Target(), args);
                System.out.println("after invoke");
                return result;
            }
        });

        $Proxy0.foo();
        $Proxy0.bar();
    }
}
